#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename	:  memMap_test
# Version	:  1.0
# Date		:  2023/12/04
# Author	:  yaoxiyao
# Email		:  yaoxiyao@kylinos.com.cn 
# History	:     
#              Version 1.0, 2023/12/04
# Function	:  支持进程内存地址的正向映射和反向映射
# Out		:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

# 测试主题
Title_Env_LTFLIB="支持进程内存地址的正向映射和反向映射"

# 目标文件
MemMapFile="memMap_test.c"
MemMapOrderFile="memMap_test"
MemMapResultFile="memMapfile.txt"

## TODO : 个性化,初始化
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestInit_LTFLIB(){
        cp ${KERNEL_SRC_DIR_KERNEL}/${MemMapFile} ${TmpTestDir_LTFLIB}
        CommRetParse_FailDiy_LTFLIB ${ERROR} "复制文件失败${KERNEL_SRC_DIR_KERNEL}/${MemMapFile}"
        cp ${KERNEL_SRC_DIR_KERNEL}/${MemMapResultFile} ${TmpTestDir_LTFLIB}
        CommRetParse_FailDiy_LTFLIB ${ERROR} "复制文件失败${KERNEL_SRC_DIR_KERNEL}/${MemMapResultFile}"
	return $TPASS
}


## TODO : 清理函数
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestClean_LTFLIB(){
        Debug_LLE "rm -rf ${TmpTestDir_LTFLIB}/${MemMapFile} ${TmpTestDir_LTFLIB}/${MemMapResultFile}"
	rm -rf ${TmpTestDir_LTFLIB}/${MemMapFile} ${TmpTestDir_LTFLIB}/${MemMapResultFile}
        return $TPASS
}


## TODO : 测试用例集
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
Testsuite_LTFLIB(){
        testcase_1
        return $TPASS
}


## TODO ： 支持进程内存地址的正向映射和反向映射
#
testcase_1(){
        cd ${TmpTestDir_LTFLIB}
        CommRetParse_LTFLIB "成功进入临时目录${TmpTestDir_LTFLIB}"

        gcc ${MemMapFile} -o ${MemMapOrderFile}
        CommRetParse_LTFLIB "成功编译文件${MemMapFile}"

        chmod 777 ${MemMapOrderFile}
        CommRetParse_LTFLIB "成功赋权文件${MemMapOrderFile}"

        chmod 777 ${MemMapResultFile}
        CommRetParse_LTFLIB "成功赋权文件${MemMapResultFile}"

        ./${MemMapOrderFile}
        CommRetParse_LTFLIB "成功执行文件${MemMapOrderFile}"

        cat ${MemMapResultFile}
        local mamMap_result=`cat ${MemMapResultFile}`
        local result_flag="test"  
        [ "Z${mamMap_result}" == "Z${result_flag}" ]
        CommRetParse_LTFLIB "支持进程内存地址的正向映射和反向映射"
}


#----------------------------------------------#

source "${LIB_LTFLIB}"
Main_LTFLIB $@
